import requests
from DrissionPage import Chromium
from fake_useragent import UserAgent

ua = UserAgent().random
driver = Chromium()

headers = {
    'User-Agent': ua,
    'Referer': 'https://www.douyin.com/',
}

tab = driver.new_tab()

tab.listen.start('aweme/v1/web/aweme/post/')

tab.get('https://www.douyin.com/user/MS4wLjABAAAAgq8cb7cn9ByhZbmx-XQDdRTvFzmJeBBXOUO4QflP96M?from_tab_name=main')

res = tab.listen.wait()

res = res.response.body

video_list = res['aweme_list']
for video in video_list:
    video_title = video['caption']
    video_url = video['video']['play_addr']['url_list'][0]
    print(video_title, video_url)
    with open(f'{video_url}.mp4', 'wb') as f:
        f.write(requests.get(video_url, headers=headers).content)
